package com.hdax.dm.mappers;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hdax.dm.entity.scheduler.DmSchedulerSeat;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public interface SchedulerSeatMapper extends BaseMapper<DmSchedulerSeat> {

    //查询某个排期下某类已经出售的座位数量
    //12691 A类（207元） 30         seatNum = 30

    @Select({
            "<script>",
                "select count(*) from dm_scheduler_seat",
                " where scheduleId=#{scheduleId} and areaLevel=#{areaLevel}",
                " and orderNo is not null and userId is not null and status !=1",
            "</script>"
    })
    int getSaleCount(@Param("scheduleId") Long scheduleId, @Param("areaLevel") Long areaLevel);

    @Select({
            "<script>",
            "select * from dm_scheduler_seat",
            " where scheduleId=#{scheduleId}",
            " and orderNo is null and userId is null and status = 1",
            "</script>"
    })
    List<DmSchedulerSeat> seatList(@Param("scheduleId") Long scheduleId);

    //修改座位的订单关联信息
    @Update({
            "update dm_scheduler_seat set orderNo=#{orderNo}, userId=#{userId}, status=#{status},updatedTime=#{updatedTime} ",
            "where scheduleId=#{scheduleId} and x=#{x} and y=#{y}"
    })
    boolean updateSeatByOrder(Map<String, Object> params);


    @Update({
            "update dm_scheduler_seat set orderNo=null, userId=null, status=1,updatedTime=now() ",
            "where orderNo=#{orderNo}"
    })
    boolean rollBackSeatByOrder(@Param("orderNo") String orderNo);
}
